#ifndef _DEVICE_H
#define _DEVICE_H
#ifndef EUTRAN_PLATFORM
#define	EUTRAN_PLATFORM
#endif
#include "msgcmn.h"

#define DEV_HDR_SIZE                    (sizeof(MSGHEADER) + sizeof(I16) * 4)
#define DEVM_CMD_LENGTH                 (BUFFER_BLOCK_SIZE - DEV_HDR_SIZE)
#define DEV_CMD_TLV_HDR_LEN             4   //2 *unsigned int
#define DEV_CMD_TLV_SGNL_LEN            8

typedef struct {
    I16 cmdType;               	    //set/get/ind/set response/get response
    I16 cmdCode;              	    //function code.
    I16 cmdIndex;               	//reserved for current usage
    I16 cmdLength;              	//when opcode is get, it is 0   
    I32 data[DEVM_CMD_LENGTH / 4];  //when opcode is get, it is all 0s
} DEV_CMD;

#define DEV_OPCODE_SET                  0x0
#define DEV_OPCODE_GET                  0x1
#define DEV_OPCODE_IND                  0x2
#define DEV_OPCODE_SET_RPL              0x10
#define DEV_OPCODE_GET_RPL              0x11
#define DEV_OPCODE_IND_RPL              0x12
#define DEV_INIT_STAT_DISCONNECT        -1
#define DEV_INIT_STAT_LAST              50       
#define DEV_INIT_STAT_DONE              51
//#ifdef LTE_DEVICE

/*
#define DEV_INIT_STAT_SMS               0
#define DEV_INIT_STAT_PA                29
#define DEV_INIT_STAT_PA_GAIN           30
#define DEV_INIT_STAT_STORAGE           1
#define DEV_INIT_STAT_BBU1_INIT         2
#define DEV_INIT_STAT_BBU2_INIT         3
#define DEV_INIT_STAT_BBU3_INIT         4
#define DEV_INIT_STAT_BBU4_INIT         5
#define DEV_INIT_STAT_BBU5_INIT         6
#define DEV_INIT_STAT_BBU6_INIT         7
#define DEV_INIT_STAT_BBU7_INIT         8

#define DEV_INIT_STAT_TX_POWER1         9
#define DEV_INIT_STAT_TX_POWER2         10
#define DEV_INIT_STAT_TX_POWER3         11
#define DEV_INIT_STAT_TX_POWER4         12
#define DEV_INIT_STAT_TX_POWER5         13
#define DEV_INIT_STAT_TX_POWER6         14
#define DEV_INIT_STAT_TX_POWER7         15


#define DEV_INIT_STAT_POWER_ON1         16
#define DEV_INIT_STAT_POWER_ON2         17
#define DEV_INIT_STAT_POWER_ON3         18
#define DEV_INIT_STAT_POWER_ON4         19
#define DEV_INIT_STAT_POWER_ON5         20
#define DEV_INIT_STAT_POWER_ON6         21
#define DEV_INIT_STAT_SET_RSSI          22
#define DEV_INIT_STAT_SMS_MSG           23
#define DEV_INIT_STAT_SMS_KEY           24
#define DEV_INIT_STAT_SYSTEM_REBOOT     25
#define DEV_INIT_STAT_SET_VAILD_PA      26

//#ifndef DATA_UPLOAD
#define DEV_INIT_STAT_LAST              27        
#define DEV_INIT_STAT_DONE              28
//#else
//#define DEV_INIT_STAT_LAST              28        
//#define DEV_INIT_STAT_DONE              29
//#endif
#define DEV_INIT_REQUEST_OFFSET         REQUEST_UPDATA_SMS  
#endif
#ifdef GSM_DEVICE
#define DEV_INIT_STAT_DISCONNECT        -1
#define DEV_INIT_STAT_SMS               0
#define DEV_INIT_STAT_STORAGE           1
#define DEV_INIT_GSM1                   2
#define DEV_INIT_GSM2                   3
#define DEV_INIT_WIFI                   4
#define DEV_INIT_SNIFFER                5
#define DEV_INIT_SNIFFER_PAR            6
#define DEV_INIT_REDET                  7
#define DEV_INIT_DO_SNIFFER             8
#define DEV_INIT_STAT_SMS_MSG           9
#define DEV_INIT_STAT_SMS_KEY           10
#define DEV_INIT_STAT_SYSTEM_REBOOT     11

//#ifndef DATA_UPLOAD
#define DEV_INIT_STAT_LAST              12       
#define DEV_INIT_STAT_DONE              13
//#else
//#define DEV_INIT_STAT_LAST              13       
//#define DEV_INIT_STAT_DONE              14
//#endif
#define DEV_INIT_STAT_PA                14
#define DEV_INIT_STAT_PA_GAIN           15
#define DEV_INIT_REQUEST_OFFSET         REQUEST_UPDATA_SMS  
#endif

#ifdef CDMA_DEVICE
#define DEV_INIT_STAT_DISCONNECT        -1
#define DEV_INIT_STAT_SMS               0
#define DEV_INIT_STAT_STORAGE           1
#define DEV_INIT_CDMA                   2
#define DEV_INIT_WIFI                   3
#define DEV_INIT_SNIFFER                4
#define DEV_INIT_SNIFFER_PAR            5
#define DEV_INIT_REDET                  6
#define DEV_INIT_STAT_SMS_MSG           7
#define DEV_INIT_STAT_SMS_KEY           8
#define DEV_INIT_STAT_LAST              5       
#define DEV_INIT_STAT_DONE              6
#define DEV_INIT_STAT_PA_GAIN           14
#define DEV_INIT_REQUEST_OFFSET         REQUEST_UPDATA_SNIFER 
#endif
*/
#define DEV_SYNC_CONF_GSM1				0
#define DEV_SYNC_CONF_GSM2				1
#define DEV_SYNC_CONF_WIFI				2
#define DEV_SYNC_CONF_SMS				3
#define DEV_SYNC_CONF_SNIFER			4
#define DEV_SYNC_CONF_PA				5
#define DEV_SYNC_CONF_SNIFFER_PAR		6
#define DEV_SYNC_CONF_DONE				7

typedef struct {
    MSGHEADER hdr;
    DEV_CMD cmd;
} DEV_MSG;

typedef struct {
    I32 code;
    I32 errcode;
    I32 id;
    I32 dcode;
} DEV_SET_RSP;
#define RESPONSE_SET_RESPONSE             0x10000000
#define RESPONSE_GET_RESPONSE             0x20000000
#define CLI_TEST                          0x30000000
#define RESPONSE_IND_RESPONSE             0x40000000
#define RESPONSE_SET_CONTINUE             0x80000000
#define RESPONSE_TYPE_MASK                0x00ffffff

/*
typedef struct
{
    U32   nbCellFreq;   // 0: for carrier 0 and 1 : for carrier 1
    I32   nbRssi;       // rssi for neighboring cell
}neighboringCellInfo_t;
*/

#define TLV_PADDING                     0x0
#define roundup8(x)                     (((U32)(x)+7)&(~7))

#define DATA_PER_MSG_NUM_MAX            50
    
#define CMD_SET_LOG_LEVEL               0x10000000 	// 32bits 

typedef struct {
	U32 cmdCode;
	U32 cmdLen;
	U32	data[0];
} CMD_FORWARD;

typedef struct {
    U32 band;
    U32 freq;
    U32 pci;
} LTE_PAR;



typedef struct {
	U32 bcc;
	U32 mcc;
	U32 mnc;
	U32 lac;
	U32 band;
	U32 carrier;
	U32 cro;
	U32 rssiMin;
	U32 thresholdDelta;
    U32 captime;
	U32 lowatt;
    U32 upatt;
    U32 cnum;
    U32 configMode;
    U32 workMode;
    U32 startFreq900;
    U32 endFreq900;
    U32 startFreq1800;
    U32 endFreq1800;
    U32 freqOffset;
}GSM_PAR;

typedef struct {
    U32 bcc;
    U32 mcc;
    U32 mnc;
    U32 carrier;
    U32 sid;
    U32 nid;
    U32 pn;
    U32 bsid;
    U32 regnum;
    U32 captime;
    U32 lowatt;
    U32 upatt;
    U32 workModel;
    U32 scanTime;
    U32 scanPeriod;
    U32 ResetModel;
    U32 freq1;
    U32 workmode1;
    U32 scantime1;
    U32 scancaptime1;
    U32 neibor1_freq1;
    U32 neibor2_freq1;
    U32 neibor3_freq1;
    U32 neibor4_freq1;
    U32 freq2;
    U32 workmode2;
    U32 scantime2;
    U32 scancaptime2;
    U32 neibor1_freq2;
    U32 neibor2_freq2;
    U32 neibor3_freq2;
    U32 neibor4_freq2;
    U32 freq3;
    U32 workmode3;
    U32 scantime3;
    U32 scancaptime3;
    U32 neibor1_freq3;
    U32 neibor2_freq3;
    U32 neibor3_freq3;
    U32 neibor4_freq3;
    U32 freq4;
    U32 workmode4;
    U32 scantime4;
    U32 scancaptime4;
    U32 neibor1_freq4;
    U32 neibor2_freq4;
    U32 neibor3_freq4;
    U32 neibor4_freq4;
} CDMA_PAR;


typedef struct
{
    U32    mcc;
    U32    mnc;
	U32    lac;
    U32    arfcn;	
    U32    psc;      
    U32    rac;
    U32    cellid;
	U32    autolac;
	U32    dac;	
	U32    txPower;
	U32    rxPower;
} WCDMA_PAR;

typedef struct {
    U8 autoBccMode;
    U8 isAuto;
    U8 hour;
    U8 minutes;
    U8 second;
    U8 snifferCycle;
    U8 reverved[2];
} SNF_PAR;

#if 0
typedef struct {
    U32 nbCellFreq;             // 0: for carrier 0 and 1 : for carrier 1
    I32 nbRssi;                 // rssi for neighboring cell
} SNF_RSLT;
#endif

typedef struct {
    I32 type;
    I32 len;
    I32 val[0];
} TLV_S;

__inline bool GetMsgRcvThreadStat();
I32 device_handle_eutran_bbu_state(I8 * buf, I32 soltId, I32 *dcode);

I32 device_interface_init(void);
I32 device_interface__exit(void);
I32 device_handle_request(I32 type, DEV_CONF * conf, I8 * buf, I32 * data,
                          I32 * dcode);
I32 device_handle_response(I8 * buf, I32 * data);
I32 device_get_init_status();
I32 device_set_init_state(I32 state);
I32 device_handle_init_all(DEV_CONF * conf, I8 * buf, I32 * dcode);
I8 *device_get_error_string(U32 id);
I32 device_handle_fep_response(I8 * buf);
I32 return_request_conf(I32 dcode, I32 ret_req);
#ifdef MODULE_TEST
void setTestMsgrcv();
#endif

#endif
